home *** CD-ROM | disk | FTP | other *** search
- {
- ***
-
- JSTEST
- Joystick Testing Utility Version 3.00
- (C)Copyright Gerard Paul Java 1996
-
- Program Source File
-
-
- This program is used to test up to two joysticks connected to the computer's
- game control adapter. It shows the computer's reponses to the joystick
- the joystick's shaft action and button presses. It can also be used to
- tune the joystick for best performance.
-
- The game adapter should be adjusted for the computer's processing speed
- in order for the joystick shaft to work properly. This program will not
- give accurate results if this requirement is not met. The adapter should
- therefore be suited to the computer in which it is installed.
-
-
- This program is free software; you may distribute and/or modify it under
- the terms of the GNU General Public License version 2 or (at your option)
- any later version, as published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful, but is
- provided "AS IS", WITHOUT ANY WARRANTY, either expressed or implied,
- including, but not limited to, warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 675 Mass Ave., Cambridge, MA 02139 USA.
-
-
- PROGRAM INFORMATION
-
- Base language: Pascal
- Compiler: Borland Turbo Pascal 5.5 or higher
- Portability: DOS-based systems only
- Requires 100% IBM computer compatibility
- No consideration for non-compatible systems
- Other information: 8086 assembly language routines included
- Assembled with the Turbo Assembler 2.0
-
-
- REVISION HISTORY:
-
- Version 1.00 - 11/13/88 [QuickBASIC 3.00] Not full-screen
- Version 2.00 - 04/15/89 [QuickBASIC 4.00b+] Center-box style
- MASM 5.0]
- Version 2.50 - 04/15/90 [Turbo Pascal 5.0+ Center-box style
- Turbo Assembler 1.0]
-
-
- ***
- }
-
-
- {$A+,B-,F-,I-,N-,R-,S-,V-}
- {$M 3072,0,1024} { 3K stack, 1K heap }
-
- program JSTEST;
- uses
- Dos,
- Crt,
- Joystick,
- ScreenRt,
- SysRt,
- Instruc,
- IntroRt,
- MenuRt,
- Error;
-
- const { untyped }
- Selected = True;
- NotSelected = False;
-
- StickA = False; { Stick identification values. }
- StickB = True;
-
- type
- Parameter1Type = string[2];
-
- ButtonStatType = string[4]; { Type of button status. }
-
- StickIDCharType = 'A'..'B'; { Characters to identify stick. }
-
- StickArgsAndOpnsType = object { Object to hold joystick args and operations. }
- StickCoordArgX: byte;
- StickCoordArgY: byte;
- StickButtonDownArg1: byte;
- StickButtonDownArg2: byte;
- DetectID: word;
- CurrentStick: boolean;
- procedure Select(StickID: boolean);
- procedure IndicateAndSaveScreen;
- procedure SelectOtherStick;
- procedure ShowTrackingWindow;
- procedure ShowButtonWindow;
- procedure TuneStick;
- end;
-
-
- const { typed }
- StickAParams: StickArgsAndOpnsType = (StickCoordArgX: 1;
- StickCoordArgY: 2;
- StickButtonDownArg1: 16;
- StickButtonDownArg2: 32;
- DetectID: DetectIDA;
- CurrentStick: StickA);
- StickBParams: StickArgsAndOpnsType = (StickCoordArgX: 4;
- StickCoordArgY: 8;
- StickButtonDownArg1: 64;
- StickButtonDownArg2: 128;
- DetectID: DetectIDB;
- CurrentStick: StickB);
-
- var
- Parameter1: Parameter1Type;
-
- BackScreenBuff: ScreenBufferType; { Save buffer for desktop. }
- AuxScreenBuffer: ScreenBufferType; { Save buffer for other screens. }
-
-
-
- {---------- Internal procedure declarations ----------}
-
-
- {----------------------------------------------------------------------------
- StickArgsAndOpnsType.Select: Sets the parameters in the parameter variable.
- This variable is of an object type and sets the correct argument values to
- the StickCoord and StickButtonDown functions. StickID identifies either
- stick A or stick B.
- ----------------------------------------------------------------------------}
-
- procedure StickArgsAndOpnsType.Select(StickID: boolean);
- begin { proc }
- case StickID of
- StickA: Self := StickAParams; { StickA: set parameters for A. }
- StickB: Self := StickBParams; { Otherwise, set parameters for B. }
- end; { case }
- end; { proc }
-
-
- {----------------------------------------------------------------------------
- InitAndDoChecks: Displays an error box in case of incorrect syntax, and
- sets the values of some variables depending on the video mode.
- ----------------------------------------------------------------------------}
-
- procedure InitAndDoChecks;
- begin { proc }
- if (LastMode = 7) or (GetEnv('BW') = '1') then
- begin { if }
- NormOptKeyAttr := $7F; { B/W and monochrome color scheme. }
- SelectedOptKeyAttr := $F;
- OptionNormTextAttr := $70;
- OptionSelectedTextAttr := $7;
- BoxAttr := $7F;
- TextNormAttr := $70;
- HelpLineTextAttr := $F;
- ErrBoxAttr := $F;
- ErrMsgAttr := $F;
- TextHighAttr := $7F;
- end { if }
- else
- begin { else }
- NormOptKeyAttr := $1B; { Color color scheme. }
- SelectedOptKeyAttr := $B;
- OptionNormTextAttr := $1E;
- OptionSelectedTextAttr := $E;
- BoxAttr := $13;
- TextNormAttr := $1E;
- HelpLineTextAttr := $71;
- ErrBoxAttr := $4F;
- ErrMsgAttr := $4E;
- TextHighAttr := $1B;
- end; { else }
-
- if Parameter1 <> Null then
- ErrAbort('Invalid syntax; pass /? for command help'); { Else invalid parameters }
-
- SetTSSRValues; { Set values for screen save/restore. }
- end; { proc }
-
-
- {---------------------------------------------------------------------------
- IndicateAndSaveScreen: Indicates the stick to be (or being) tested in the
- bottom line. Saves the screen in BackScreenBuff.
- ---------------------------------------------------------------------------}
-
- procedure StickArgsAndOpnsType.IndicateAndSaveScreen;
- var
- CharID: char;
-
- begin { proc }
- case CurrentStick of
- StickA: CharID := 'A';
- StickB: CharID := 'B';
- end; { case }
-
- TextAttr := TextHighAttr;Window(79,25,80,25);
- Write(CharID);
- SaveScreen(BackScreenBuff);
- end; { proc }
-
-
- {---------------------------------------------------------------------------
- IndicateError: Displays an error box with a specified message and an
- instruction to retry or abort. It contains code to check for the R and
- Esc keystrokes.
- --------------------------------------------------------------------------}
-
- procedure IndicateError(Msg1: ErrStrType;var Keystroke: char);
- begin
- SaveScreen(AuxScreenBuffer);
-
- ErrBox(Msg1,
- 'Press R to retry, or Esc to cancel',Instruct);
-
- repeat
- Keystroke := UpCase(GetKeyNoExt);
- until (Keystroke = RetryKey) or (Keystroke = Esc);
-
- RestoreScreen(AuxScreenBuffer);
- end;
-
-
- {---------------------------------------------------------------------------
- DisconnectError: Returns an error message if contact with the joystick
- is lost.
- ---------------------------------------------------------------------------}
-
- procedure DisconnectError(var Response: char);
- begin
- IndicateError('Error: unable to detect joystick',Response);
- end;
-
-
- {----------------------------------------------------------------------------
- SelectOtherStick: Attempts to select the other joystick for testing if it
- is found. If not, a box appears indicating it's not there, and the switch
- is aborted.
- ---------------------------------------------------------------------------}
-
- procedure StickArgsAndOpnsType.SelectOtherStick;
- var
- TerminateLoop: boolean;
- OtherStickPresent: boolean;
- Response: char;
-
- begin { proc }
- Window(2,25,80,25);Write('Wait. . .');
-
- TerminateLoop := False;
-
- repeat
- case CurrentStick of
- StickA: OtherStickPresent := StickIsPresent(DetectIDB);
- StickB: OtherStickPresent := StickIsPresent(DetectIDA);
- end; { case }
-
- if OtherStickPresent then
- begin
- RestoreScreen(BackScreenBuff);
- Select(not CurrentStick);
- IndicateAndSaveScreen;
- TerminateLoop := True;
- end { if }
- else
- begin
- IndicateError('Error detecting other joystick',Response);
-
- RestoreScreen(AuxScreenBuffer);
-
- if Response = Esc then
- begin
- RestoreScreen(BackScreenBuff);
- TerminateLoop := True;
- end; { if }
- end; { else }
- until TerminateLoop;
- end; { proc }
-
-
- {---------------------------------------------------------------------------
- ShowHelpScreen: The JSTEST help system.
- ---------------------------------------------------------------------------}
-
- procedure ShowHelpScreen(ScreenNo: byte);
- begin { proc }
- Window(1,1,80,25);
- SaveScreen(AuxScreenBuffer); { Save screen. }
- JustSeeBox;
- {$IFDEF Cyan}
- TextAttr := $6F;
- TextNormAttr := $6E;
- TextHighAttr := $6F;
- {$ELSE}
- TextAttr := BoxAttr;
- {$ENDIF}
-
- case ScreenNo of
- 0: begin
- DrawBox(3,2,78,24,DoubleLine);
- GotoXY(31,2);Write(' Help: Help System ');
- Window(5,4,78,25);TextAttr := TextNormAttr;
-
- Writeln('At almost any point in this program, press F1 for help (help is not');
- Writeln('available at error and instruction boxes). Each help screen contains');
- Writeln('instructions on what to do at the point from where it was invoked.');
- Writeln;
- Writeln('The help screens of the test windows also indicate the expected results');
- Writeln('and/or the results that could mean one or more defects in the stick. If');
- Writeln('results don''t happen when they''re expected, or the defect symptoms do,');
- Writeln('have the stick serviced. (This program is for standard, 2-button joy-');
- Writeln('sticks only. The test procedures are not designed for other devices,');
- Writeln('even though other devices that connect to the game adapter could be');
- Writeln('erratically detected as joysticks.) The game adapter and joystick(s)');
- Writeln('must be IBM or compatible, and the adapter must be adjusted for or');
- Writeln('expected to be used at the computer''s processing speed (adapters sup-');
- Writeln('plied with the computer or a clone of it are already adjusted), and all');
- Writeln('connections must be good for reliable results.');
- Writeln;
- Writeln('See the manual for details.');
- Writeln;
- end; { 0 }
- 1: begin
- DrawBox(3,6,78,19,DoubleLine);
- GotoXY(30,6);Write(' Help: Menu Operation ');
- Window(5,8,78,20);TextAttr := TextNormAttr;
- Writeln('The Up and Down cursor keys move the selection bar up and down respect-');
- Writeln('ively. Home and End move it to the first and last options respectively.');
- Writeln('Enter executes the option indicated by the bar.');
- Writeln;
- Writeln('Pressing the highlighted letters directly executes their corresponding');
- Writeln('options.');
- Writeln;
- Writeln('The bottom line of the screen shows a description of the function of the');
- Writeln('option indicated by the selection bar.');
- end; { 1 }
- 2: begin
- DrawBox(3,3,78,23,DoubleLine);
- GotoXY(28,3);Write(' Help: Tracking Window ');
- Window(5,5,78,24);
- TextAttr := TextNormAttr;
- Writeln('This test cannot be performed accurately if the game adapter is not adj-');
- Writeln('usted for the computer''s processing speed. This information assumes');
- Writeln('this requirement is met.');
- Writeln;
- Writeln('The cursor should follow the movements of the joystick shaft, and be');
- Writeln('outside the inner box box when the shaft is placed at extreme positions');
- Writeln('Try tuning the joystick before this test. Use this procedure only after');
- Writeln('tuning, or if a tuning error occurs and you are told to test the shaft.');
- Writeln('If an error occurs during tuning, or still the above cannot be met, the');
- Writeln('stick is defective. Without tuning, that the shaft might appear to work');
- Writeln('normally even if it might really be defective. Such a joystick will');
- Writeln('cause a tuning error. In this case, use this test to determine the');
- Writeln('shaft problem. Also, vibrations without shaft motion are possible.');
- Writeln('Such vibrations are normal.');
- Writeln;
- Writeln('To return to the menu, press Esc, X, or Q.');
- end; { 2 }
- 3: begin
- DrawBox(3,5,78,21,DoubleLine);
- GotoXY(30,5);Write(' Help: Button Testing ');
- Window(5,7,78,24);TextAttr := TextNormAttr;
- Writeln('The indicator should read Down when its button is pressed, Up if not.');
- Writeln('Any other behavior indicates a malfunction. The buttons should work');
- Writeln('correctly regardless of the adapter''s speed setting. If your joystick');
- Writeln('has only one button, the Button 2 indicator must always read Up.');
- Writeln;
- Writeln('(Some joysticks'' buttons can behave in such manner that when they are');
- Writeln('held down, they appear to be repeatedly pressed then released. Should');
- Writeln('this feature be active, the corresponding indicator should repeatedly');
- Writeln('switch between Up and Down when a button is held down, Up otherwise.)');
- Writeln;
- Writeln('Press Esc, X, or Q to return to the menu.');
- Writeln;
- end; { 3 }
- 4: begin
- DrawBox(3,3,78,23,DoubleLine);
- GotoXY(29,3);Write(' Help: Tuning Window ');
- Window(5,5,78,24);TextAttr := TextNormAttr;
- Writeln('X and Y refer to the joystick''s horizontal and vertical coordinates');
- Writeln('respectively. The coordinates may indicate slight shaft vibration even');
- Writeln('with no shaft motion along any axis or both axes.');
- Writeln;
- Writeln('This procedure is applicable only to joysticks with tuning controls.');
- Writeln('Follow the instruction. The value must increase or decrease depending');
- Writeln('on its tuning control''s direction of movement when the shaft is kept');
- Writeln('centered. When the indicators show the stated values, press a key to');
- Writeln('test the joystick''s centering. The stated numbers will change');
- Writeln('accordingly, or if the joystick is tuned, a message box will appear,');
- Writeln('indicating the joystick is now centered. (Deviations of at most 7');
- Writeln('from the stated values are tolerated because of the vibrations.) If');
- Writeln('a shaft error occurs, the joystick is malfunctioning. Execute "Shaft');
- Writeln('testing" from the menu to determine the problem.');
- Writeln;
- Writeln('Press Q, X, or Esc to return to the menu.');
- end; { 4 }
- end; { case }
-
- Writeln;
- TextAttr := TextHighAttr;Write(ContMsg); { Display message. }
- WaitForKeypress;
- RestoreScreen(AuxScreenBuffer); { Get rid of help. }
- end; { proc }
-
-
- {---------------------------------------------------------------------------
- CommandHelp: Displays help information on the JSTEST command and startup
- info.
- ---------------------------------------------------------------------------}
-
- procedure CommandHelp;
- begin
- Assign(Output,'');Rewrite(Output);
- Writeln('Help on the JSTEST command:');
- Writeln;
- Writeln('Command syntax: JSTEST [/?]');
- Writeln;
- Writeln('To bring up the main program screen, type JSTEST with no parameters. The');
- Writeln('program will determine the number of joysticks present (up to 2) and will');
- Writeln('select the proper stick. The program menu will not come up if no stick is');
- Writeln('found at startup. If both are present, the program will select joystick A.');
- Writeln('(Some adapters have two game ports into which separate A and B joysticks can');
- Writeln('be plugged. No error is therefore reported for as long as at least one joy-');
- Writeln('stick is detected.) Detection errors mean problems with the joystick(s) if');
- Writeln('it/they is/are attached well. This program is for joysticks only. Other');
- Writeln('devices that connect to the game adapter could be erratically detected, but');
- Writeln('the test procedures are not designed for these.');
- Writeln;
- Writeln('Set the value of the CGASNOWCHECK environment variable to 1 to suppress "snow"');
- Writeln('on old CGAs. Set the value of the BW environment variable to 1 to bring the');
- Writeln('program up in black and white mode. (From DOS, issue SET CGASNOWCHECK=1 and/');
- Writeln('or SET BW=1.)');
- Writeln;
- Writeln('No parameters other than /? are accepted.');
- Writeln;
- Writeln('JSTEST Version 3.00: Copyright Gerard Paul Java 1996');
- end; { proc }
-
-
- {---------------------------------------------------------------------------
- ShowTrackingWindow: Opens a window containing a cursor to track the shaft's
- movements.
- ---------------------------------------------------------------------------}
-
- procedure StickArgsAndOpnsType.ShowTrackingWindow;
- const
- xMaxPos = 47;
- yMaxPos = 19;
-
- var
- xRange: word;
- yRange: word;
-
- xPos: byte;
- yPos: byte;
-
- Keystroke: char;
-
- ExitTracking: boolean;
-
- begin
- Window(1,1,80,25);
-
- JustSeeBox;
-
- InstBox(13,16,'Center the joystick shaft',
- CancelOrContMsg);
-
- Beep(900,100);
- Keystroke := GetKeyNoExt;
-
- RestoreScreen(BackScreenBuff); { Saved earlier at menu. }
-
- if Keystroke <> Esc then
- begin
- { For the range computation and plotting, the coordinates are
- increased by 1 to increase the minimum value to 1. This will
- avoid problems with range computation with zero coordinates.
- But because minimum coordinates for both axes are now 1, to
- plot more accurately, the coordinates to be plotted must also
- be increased by 1. }
-
- XRange := (StickCoord(StickCoordArgX)+1)*2; { Determine ranges. }
- YRange := (StickCoord(StickCoordArgY)+1)*2;
-
- Window(1,1,80,25);
-
- TextAttr := BoxAttr;DrawBox(4,3,77,23,DoubleLine);
- DivideBox(52,3,23);
- GotoXY(24,3);Write(' Tracking ');
- ShowInstTitle(57,3);
- TextAttr := TextNormAttr;
- Window(54,5,76,24);
- Writeln('See whether the');
- Writeln('cursor correctly');
- Writeln('follows shaft move-');
- Writeln('ments. The cursor');
- Writeln('must be outside the');
- Writeln('inner box when the');
- Writeln('shaft is placed at');
- Writeln('extreme positions.');
- Writeln('Use this procedure');
- Writeln('only after tuning');
- Writeln('the shaft or if an');
- Writeln('error occurs during');
- Writeln('tuning. If the above');
- Writeln('conditions do not');
- Writeln('occur, or a tuning');
- Writeln('error occurs, the');
- Writeln('stick is bad.');
-
- Window(5,4,51,22);ClrScr; { Make the cursor yellow. }
- DrawBox(9,5,36,15,SingleLine);
-
- ExitTracking := False;
-
- SetCursor($000F);
-
- repeat
- if StickIsPresent(DetectID) then
- begin
- xPos := Trunc(((StickCoord(StickCoordArgX)+1)/xRange)*46)+1;
- yPos := Trunc(((StickCoord(StickCoordArgY)+1)/yRange)*18)+1;
-
- if xPos > xMaxPos then { Ensure cursor stays in }
- xPos := xMaxPos; { tracking window. }
-
- if yPos > yMaxPos then
- yPos := yMaxPos;
-
- GotoXY(xPos,yPos);
-
- if KeyPressed then
- begin
- Keystroke := UpCase(ReadKey);
-
- case Keystroke of
- ExtKey : if ReadKey = F1 then
- begin
- SetCursor($FFFF);
- ShowHelpScreen(2);
- SetCursor($000F);
- end;
- Esc,
- ExitKey,
- AltExitKey : ExitTracking := True;
- end; { case }
- end; { if KeyPressed }
- end
- else
- begin
- SetCursor($FFFF);
- DisconnectError(Keystroke);
- if Keystroke = Esc then
- ExitTracking := True
- else
- begin
- Window(5,4,51,22);
- SetCursor($000F);
- end;
- end;
- until ExitTracking;
-
- SetCursor($FFFF);
- end; { if not Esc }
- end; { proc }
-
-
- {----------------------------------------------------------------------------
- ShowButtonWindow: Displays a window showting statuses of the joystick
- buttons.
- ----------------------------------------------------------------------------}
-
- procedure StickArgsAndOpnsType.ShowButtonWindow;
- var
- Keystroke: char;
- ExitTest: boolean;
-
- {---------------------------------------------------------------------------
- ButtonStat: Reports the statuses of the joystick buttons. Returns "Up "
- if indicated button is not pressed, "Down" otherwise.
- ---------------------------------------------------------------------------}
-
- function ButtonStat(TrigArg: byte): ButtonStatType;
- begin { ButtonStat }
- if StickButtonDown(TrigArg) then
- ButtonStat := 'Down'
- else
- ButtonStat := 'Up ';
- end; { ButtonStat }
-
- begin { proc }
- TextAttr := BoxAttr;Window(1,1,80,25);DrawBox(8,8,73,17,DoubleLine);
- DivideBox(30,8,17);
-
- GotoXY(10,8);Write(' Buttons'' Statuses ');
- ShowInstTitle(45,8);
-
- TextAttr := TextNormAttr;
-
- Window(32,12,72,17);
- Writeln('See whether the indicators correctly'); { Instruction. }
- Writeln('reflect the buttons'' statuses.'); { This should be }
- { enough. }
- Window(13,12,58,16);
- Writeln('Button 1:'); { Button indicators. }
- Write('Button 2:');
-
- ExitTest := False;
-
- TextAttr := TextHighAttr;
- repeat
- if StickIsPresent(DetectID) then
- begin
- Window(23,12,67,19);
- TextAttr := TextHighAttr;
- Writeln(ButtonStat(StickButtonDownArg1)); { Display button statuses. }
- Write(ButtonStat(StickButtonDownArg2));
-
- if KeyPressed then
- begin
- Keystroke := UpCase(ReadKey);
-
- case Keystroke of
- ExtKey : if ReadKey = F1 then
- ShowHelpScreen(3);
- ExitKey,
- AltExitKey,
- Esc : ExitTest := True;
- end; { case }
- end; { if KeyPressed }
- end
- else
- begin
- DisconnectError(Keystroke);
- if Keystroke = Esc then
- ExitTest := True;
- end;
- until ExitTest;
- end; { proc }
-
-
- {----------------------------------------------------------------------------
- TuneStick: Instructs the user to adjust the joystick's tuning controls
- according to its recommendation.
- ---------------------------------------------------------------------------}
-
- procedure StickArgsAndOpnsType.TuneStick;
- var
- Keystroke: char;
- ExitLoop: boolean;
- Row: byte;
- xMin,yMin: word;
- xMax,yMax: word;
- xCen,yCen: word;
- xRec,yRec: word;
-
- {--------------------------------------------------------------------------
- GetMinMax: Prompts the user for appropriate shaft action and retrieves
- the minimum and maximum diagonal coordinates.
- --------------------------------------------------------------------------}
-
- procedure GetMinMax(var xMin,yMin,xMax,yMax: word;var Keystroke: char);
- begin
- SaveScreen(AuxScreenBuffer);
- if Keystroke <> Esc then
- begin
-
- InstBox(13,16,'Move the shaft to the upper left corner',
- CancelOrContMsg);
-
- Keystroke := GetKeyNoExt;
- RestoreScreen(AuxScreenBuffer);
-
- if Keystroke <> Esc then
- begin
- xMin := StickCoord(StickCoordArgX); { Get minimum coordinates. }
- yMin := StickCoord(StickCoordArgY);
-
- InstBox(13,16,'Move the shaft to the lower right corner',
- CancelOrContMsg);
-
- Keystroke := GetKeyNoExt;
- RestoreScreen(AuxScreenBuffer);
-
- if Keystroke <> Esc then
- begin
- xMax := StickCoord(StickCoordArgX); { Get maximum coordinates. }
- yMax := StickCoord(StickCoordArgY);
- end;
- end;
- end;
- end;
-
-
- {--------------------------------------------------------------------------
- TestCentering: Calculates the midpoint coordinates according to the min
- and max coordinates passed as parameters.
- --------------------------------------------------------------------------}
-
- procedure TestCentering(var xMin,yMin,xMax,yMax,
- xRec,yRec: word);
- begin
- xRec := (xMin+xMax) div 2; { Calculate midpoint. }
- yRec := (yMin+yMax) div 2;
- end;
-
-
- {--------------------------------------------------------------------------
- TuneInstruc: Prints the the recommended values in the instruction section.
- --------------------------------------------------------------------------}
-
- procedure TuneInstruc(xRec,yRec: word);
- begin
- Window(34,14,72,17);
- TextAttr := TextNormAttr;
- Writeln(' X=',xRec:5,' Y=',yRec:5);
- end;
-
- begin
- SaveScreen(AuxScreenBuffer);
- InstBox(13,16,'Make sure tuning controls are away from extreme positions',
- CancelOrContMsg);
-
- Keystroke := GetKeyNoExt;
- RestoreScreen(AuxScreenBuffer);
-
- if Keystroke <> Esc then
- begin
- GetMinMax(xMin,yMin,xMax,yMax,Keystroke);
-
- if Keystroke <> Esc then
- begin
- TestCentering(xMin,yMin,xMax,yMax,xRec,yRec);
-
- TextAttr := BoxAttr;Window(1,1,80,25);DrawBox(8,8,73,17,DoubleLine);
- DivideBox(30,8,17);
-
- GotoXY(13,8);Write(' Coordinates '); { Titles. }
- ShowInstTitle(45,8);
-
- TextAttr := TextNormAttr;Window(32,10,72,17);
- Writeln('Keep the shaft centered and adjust the'); { Instruction. }
- Writeln('tuning controls to set the coordinates'); { This should be }
- Writeln('to as close to these values as possible:'); { enough. }
-
- TuneInstruc(xRec,yRec);
-
- Window(16,12,26,15);
- Writeln('X=');
- Write('Y=');
-
- ExitLoop := False;
-
- repeat
- if StickIsPresent(DetectID) then
- begin
- TextAttr := TextHighAttr;
- Window(19,12,35,19);
- Writeln(StickCoord(StickCoordArgX):5); { Show coordinates. }
- Write(StickCoord(StickCoordArgY):5);
-
- if KeyPressed then
- begin
- Keystroke := UpCase(ReadKey);
-
- case Keystroke of
- ExtKey: if ReadKey = F1 then
- ShowHelpScreen(4);
- Esc,
- ExitKey,
- AltExitKey: ExitLoop := True;
- else
- begin
- SaveScreen(AuxScreenBuffer);
-
- InstBox(12,15,'Center the shaft',
- CancelOrContMsg);
- Keystroke := GetKeyNoExt;
- RestoreScreen(AuxScreenBuffer);
-
- if Keystroke <> Esc then
- begin
- xCen := StickCoord(StickCoordArgX);
- yCen := StickCoord(StickCoordArgY);
-
- GetMinMax(xMin,yMin,xMax,yMax,Keystroke);
-
- if Keystroke <> Esc then
- if (xMin >= xCen) or (xMax <= xCen) or
- (yMin >= yCen) or (yMax <= yCen) then
- begin
- TextAttr := ErrBoxAttr;
- Window(1,1,80,25);
- DrawBox(16,5,65,20,DoubleLine);Window(18,7,71,21);
- TextAttr := ErrMsgAttr;
- Writeln('Error: Shaft malfunction. Stick cannot be');
- Writeln('tuned.');
- Writeln;
- Writeln('The joystick is not properly sending the');
- Writeln('signals to the computer. The coordinates');
- Writeln('therefore do not correspond to the actual');
- Writeln('shaft position.');
- Writeln;
- Writeln('Ensure the joystick is properly connected,');
- Writeln('then execute "Shaft testing" to determine');
- Writeln('the problem.');
- Writeln;
- TextAttr := ErrBoxAttr;
- Writeln('Press a key to return to the main menu');
- ErrSound;
- WaitForKeyPress;
- ExitLoop := True;
- end
- else
- begin
- TestCentering(xMin,yMin,xMax,yMax,xRec,yRec);
-
- if (xRec >= xCen-7) and (xRec <= xCen+7) and
- (yRec >= yCen-7) and (yRec <= yCen+7) then
- begin
- InstBox(12,15,'The joystick is tuned',
- 'Press a key to return to the main menu');
-
- WaitForKeyPress;
- ExitLoop := True;
- end
- else
- TuneInstruc(xRec,yRec);
- end;
- end
- end;
- end; { case }
- end; { if KeyPressed }
- end
- else
- begin
- DisconnectError(Keystroke);
- if Keystroke = Esc then
- ExitLoop := True;
- end;
- until ExitLoop;
- end;
- end;
- end; { proc }
-
-
- {---------------------------------------------------------------------------
- ProgInterface: Sets up the screen and waits for input. This procedure
- contains the screen setup and the pre-test interface.
- ---------------------------------------------------------------------------}
-
- procedure ProgInterface;
- var
- Postn: byte;
- Keystroke: char;
- Menu: MenuType;
- HelpSignal: boolean;
-
- StickArgsAndOpns: StickArgsAndOpnsType; { Arguments to the joystick
- functions. }
-
- {---------------------------------------------------------------------------
- SelectDefaultStick: Selects the first joystick it finds. It sets the
- parameter variable, but indication is done by the IntroScreen procedure,
- since the screen has to be done first. This is called so that if no
- sticks are found, the main screen won't come up.
- ---------------------------------------------------------------------------}
-
- procedure SelectDefaultStick;
- var
- Error: boolean;
-
- begin
- InitAndCheckGameSys(Error); { Attempt to init and check for a joystick. }
-
- {$IFDEF NoStick}
- if not Error then
- {$ELSE}
- if Error then { No sticks nor adapter present? }
- {$ENDIF}
- ErrAbort('Error: no joysticks detected')
- else if StickIsPresent(DetectIDA) then { How 'bout stick A? }
- StickArgsAndOpns.Select(StickA)
- else
- StickArgsAndOpns.Select(StickB); { Gotta be stick B. }
- end; { proc }
-
-
- {--------------------------------------------------------------------------
- IntroScreen: Draws the introductory box. This box disappears when a key
- other than F1 is pressed. F1 brings up a screen showing information on
- the built-in help system.
- --------------------------------------------------------------------------}
-
- procedure IntroScreen;
- var
- Keystroke: char;
- TerminateLoop: boolean;
- Postn: byte;
-
- begin
- DrawDesktop;
- TextAttr := TextNormAttr;GotoXY(2,1);Writeln('JSTEST Version 3.00');
- SaveScreen(BackScreenBuff);
-
- DrawIntroBox; { DrawBox(13,8,68,15,DoubleLine) }
-
- TextAttr := TextNormAttr;
- Writeln('JSTEST');
- Writeln('Joystick Testing and Tuning Utility Version 3.00');
- Writeln('(C)Copyright Gerard Paul Java 1996');
- Writeln;
- TextAttr := TextHighAttr;
- Write('Press F1 for help on help, any other key to continue');
-
- TerminateLoop := False;
-
- repeat
- Keystroke := UpCase(ReadKey);
- if Keystroke = ExtKey then
- begin
- if ReadKey = F1 then
- ShowHelpScreen(0)
- else
- TerminateLoop := True;
- end
- else
- TerminateLoop := True;
- until TerminateLoop;
-
- Window(1,1,80,25);
- RestoreScreen(BackScreenBuff);
-
- GotoXY(2,25);Write('F1');
- TextAttr := TextNormAttr;Write('-help');
- GotoXY(58,25);Write(#179' Selected joystick:');
- StickArgsAndOpns.IndicateAndSaveScreen;
- end; { proc }
-
- begin { ProgInterface }
- SelectDefaultStick;
-
- IntroScreen; { Startup screen. }
-
- Menu.Init;
-
- with Menu do
- begin
- AddItem('Select other ^joystick','Selects other joystick for testing');
- AddItem('^Shaft testing','Shows responses to joystick movements');
- AddItem('^Button testing','Brings up the button testing window');
- AddItem('^Tune joystick','Brings up the joystick tuning window');
- AddItem('E^xit program','Exits program');
- end;
-
- Menu.SetScreenPos(25,8);
-
- Postn := 1;
-
- repeat
- Menu.Show;
-
- repeat
- Menu.Operate(Postn,HelpSignal);
- if HelpSignal then
- ShowHelpScreen(1);
- until not HelpSignal;
-
- RestoreScreen(BackScreenBuff);
-
- case Postn of { Execute options according to row. }
- 1: StickArgsAndOpns.SelectOtherStick; { saves screen }
- 2: StickArgsAndOpns.ShowTrackingWindow;
- 3: StickArgsAndOpns.ShowButtonWindow;
- 4: StickArgsAndOpns.TuneStick;
- end; { case Postn }
-
- RestoreScreen(BackScreenBuff);
- until (Postn = 5) or (Postn = 0); { 5=last item, 0=Esc pressed. }
-
- Release(HeapOrg); { Free heap. }
- end; { proc }
-
-
- {---------------------------------------------------------------------------
- JSTEST: This is the main program, consisting mainly of procedure calls.
- ---------------------------------------------------------------------------}
-
- begin { program }
- Parameter1 := ParamStr(1); { Store parameter. }
-
- if Parameter1 = '/?' then { Command help parameter? }
- CommandHelp { Yes, show it. }
- else
- begin
- CheckBreak := BreakOff; { Don't wanna break it. }
-
- ScreenInit;
-
- if (GetEnv('CGASNOWCHECK') = '1') and (LastMode <> Mono) then
- CheckSnow := SnowCheckOn
- else
- CheckSnow := SnowCheckOff;
-
- InitAndDoChecks; { Do checks. }
- ProgInterface; { Setup screen and menu. }
-
- TerminateProg(0); { Terminate. }
- end; { else }
- end. { program }
-